
import axios from "axios";

const request = axios.create
(
    {
        baseURL: '/api',
        timeout: 10000
    }
);

request.interceptors.response.use
(
    response => 
    {
        const data = response.data
        if 
        (
            !(
                data.hasOwnProperty('stat') &&
                data.hasOwnProperty('msg') &&
                data.hasOwnProperty('data')
            )
        )
        {
            alert('服务器返回数据格式错误, 这不是俺的服务器!')
        }

        return data;
    },
    error => 
    {
        return Promise.reject(error);
    }
);

export const getApi = (url, params) => request.get(url, { params })

export default request

